/* Azevedo/Benegal/Holman, 2014-2020 CES analysis

Do file for cleaning the raw data files and appending. Doing this off dropbox b/c space issues. 

2014: CCES14_Common_Content_Validated.dta
2016: CCES16_Common_OUTPUT_Feb2018_VV.dta
2018: cces18_common_vv.dta
2020: CES20_Common_OUTPUT_vv.dta

*/

******************************************************
******************* 2020 CES *************************
******************************************************

clear
**set wd
use CES20_Common_OUTPUT_vv.dta
set scheme plotplain
set more off

gen survyr=2020
gen cweight2020=commonweight
gen vweight2020=vvweight

/* Main DVs 
CC20_333a: give EPA power to regulate CO2 (same as in 2018)
CC20_333b: minimum renewable mandate for states
CC20_333c: strengthen CAA/CWA protection (even if costing jobs)
CC20_333d: raise fuel efficiency */

tab CC20_333a, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 CO2reg 

tab CC20_333b, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 REmandate

tab CC20_333c, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 EPA

tab CC20_333d, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 fuel20

label variable CO2reg "Give EPA power to regular CO2"
label variable REmandate "Renewable energy mandate for states"
label variable EPA "Strengthen EPA enforcement of CWA/CAA"
label variable fuel "Raise fuel efficiency standard"

gen sex=.
label define sex 0 "Male" 1 "Female"
replace sex=0 if gender==1
replace sex=1 if gender==2
label values sex sex

tab race
tab hispanic
tab educ
tab religpew

// 3 point PID scale

gen partyid3=.
replace partyid3=1 if CC20_433a==1
replace partyid3=2 if CC20_433a==2
tab partyid3 CC20_433a
replace partyid3=1 if CC20_433b==1
replace partyid3=2 if CC20_433b==2
replace partyid3=3 if CC20_433b==3
replace partyid3=3 if CC20_433b==8

label define partyid3 1 "Democratic" 2 "Republican" 3 "Independent/No pref"
label values partyid3 partyid3
tab partyid3 CC20_433a
tab partyid3 CC20_433b

// ideology - combine very/somewhat liberal & conservative, omit not sure
gen ideo3=ideo5
recode ideo3(2=1)
recode ideo3(5=4)
recode ideo3(6=.)
recode ideo3(3=2)
recode ideo3(4=3)
tab ideo3 ideo5, m

label define ideo3 1 "Liberal" 2 "Moderate" 3 "Conservative"
label values ideo3 ideo3
tab ideo3


/* Racial resentment  
2 items from the Kinder/Sanders RR scale (Special favors/Generations of slavery items). 
*/

factor CC20_441a CC20_441b
tab CC20_441a, m
// need to reverse this one
gen favors=.
replace favors=1 if CC20_441a==5
replace favors=2 if CC20_441a==4
replace favors=3 if CC20_441a==3
replace favors=4 if CC20_441a==2
replace favors=5 if CC20_441a==1
tab favors CC20_441a, m

gen generations=CC20_441b
factor favors generations
gen resentment=(favors + generations)/2

/* FIRE
Same 2 items - white people have advantages + racial problems are rare/isolated */

factor CC20_440a CC20_440b

gen advantages=CC20_440a
// need to reverse second item
gen isolated=.
replace isolated=1 if CC20_440b==5
replace isolated=2 if CC20_440b==4
replace isolated=3 if CC20_440b==3
replace isolated=4 if CC20_440b==2
replace isolated=5 if CC20_440b==1
tab isolated CC20_440b, m

factor advantages isolated

gen FIRE=(advantages + isolated)/2
factor resentment FIRE

/* Hostile sexism - need to reverse both items. FYI, for all of these RR/ASI items, they've changed the scale so 1 is strong agree | 5 is strong disagree */

factor CC20_440c CC20_440d

gen control=.
replace control=1 if CC20_440c==5
replace control=2 if CC20_440c==4
replace control=3 if CC20_440c==3
replace control=4 if CC20_440c==2
replace control=5 if CC20_440c==1
tab control CC20_440c, m

gen offended=.
replace offended=1 if CC20_440d==5
replace offended=2 if CC20_440d==4
replace offended=3 if CC20_440d==3
replace offended=4 if CC20_440d==2
replace offended=5 if CC20_440d==1
tab offended CC20_440d, m

factor control offended

gen hostilesexism=(control + offended)/2

// age categories 
gen age=2020-birthyr
label var age "Age"

// education
gen educlevel=educ
recode educlevel(2=1)
recode educlevel(3=2)
recode educlevel(4=3)
recode educlevel(5=4)
recode educlevel(6=5)
tab educlevel educ, m
label define educlevel 1 "HS or less" 2 "Some college" 3 "2 year/associate's degree" 4 "4 year/Bachelor's degree" 5 "Post-grad", replace
label values educlevel educlevel

// income
recode faminc(97=.n)


keep caseid survyr cweight2020 vweight2020 CO2reg REmandate EPA fuel20 sex partyid3 pid7 ideo5 ideo3 favors generations resentment advantages isolated FIRE control offended hostilesexism age educlevel inputstate race hispanic educ religpew CC20_hisp* CC20_asian* CC20_303 faminc

save CES20trimmed.dta, replace


******************************************************
******************* 2018 CES *************************
******************************************************

set more off
use cces18_common_vv.dta, clear

gen survyr=2018
gen cweight2018=commonweight
gen vweight2018=vvweight

/* Main DVs 
CC18_415a: give EPA power to regulate CO2 (same as in 2018)
CC18_415c: minimum renewable mandate for states
CC18_415d: strengthen CAA/CWA protection (even if costing jobs)
CC18_415ad: raise fuel efficiency - REVERSE CODE, this is asked as "lower fuel efficiency" */

tab CC18_415a, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 CO2reg 

tab CC18_415c, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 REmandate

tab CC18_415d, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 EPA

// reverse code

tab CC18_415b, gen(support)
drop support1
label define support2 0 "Support" 1 "Oppose", replace
label values support2 support2
rename support2 fuel18

label variable CO2reg "Give EPA power to regular CO2"
label variable REmandate "Renewable energy mandate for states"
label variable EPA "Strengthen EPA enforcement of CWA/CAA"
label variable fuel "LOWER fuel efficiency standard"

// demographics

gen sex=.
label define sex 0 "Male" 1 "Female"
replace sex=0 if gender==1
replace sex=1 if gender==2
label values sex sex

tab race
tab hispanic
tab educ
tab religpew

// 3 point PID scale

gen partyid3=.
tab pid7, m
replace partyid3=1 if pid7==1
replace partyid3=1 if pid7==2
replace partyid3=1 if pid7==3
replace partyid3=3 if pid7==4
replace partyid3=3 if pid7==8
replace partyid3=2 if pid7==5
replace partyid3=2 if pid7==6
replace partyid3=2 if pid7==7
tab pid7 partyid3 , m

label define partyid3 1 "Democratic" 2 "Republican" 3 "Independent/No pref"
label values partyid3 partyid3
tab partyid3 pid7

// ideology - combine very/somewhat liberal & conservative, omit not sure

gen ideo3=ideo5
recode ideo3(2=1)
recode ideo3(5=4)
recode ideo3(6=.)
recode ideo3(3=2)
recode ideo3(4=3)
tab ideo3 ideo5, m

label define ideo3 1 "Liberal" 2 "Moderate" 3 "Conservative"
label values ideo3 ideo3
tab ideo3


/* Racial resentment  
Kinder/Sanders scale has all 4 items here - make a 2 item scale to keep consistent with the 2020 CES, but also the 4 item expanded */

// favor item - highest resentment response is 1 - need to reverse
tab CC18_422e, m
gen favors=.
replace favors=1 if CC18_422e==5
replace favors=2 if CC18_422e==4
replace favors=3 if CC18_422e==3
replace favors=4 if CC18_422e==2
replace favors=5 if CC18_422e==1
tab favors CC18_422e, m

// generations item - highest resentment item is 5
tab CC18_422f, m
gen generations=CC18_422f

// deserve item - highest resentment item is 5
tab CC18_422g, m
gen deserve=CC18_422g 

// trying item - highest resentment item is 1, need to reverse
tab CC18_422h , m
gen trying=.
replace trying=1 if CC18_422h==5
replace trying=2 if CC18_422h==4
replace trying=3 if CC18_422h==3
replace trying=4 if CC18_422h==2
replace trying=5 if CC18_422h==1
tab trying CC18_422h, m

factor favors generations deserve trying

gen resentment=(favors + generations)/2

gen resentexpand=(favors + generations + deserve + trying)/4

tab CC18_422a , m
gen advantages=CC18_422a 
label var advantages "FIRE scale advantages item (5=highest resentment)"

tab CC18_422b, m
gen isolated=.
replace isolated=1 if CC18_422b==5
replace isolated=2 if CC18_422b==4
replace isolated=3 if CC18_422b==3
replace isolated=4 if CC18_422b==2
replace isolated=5 if CC18_422b==1
tab isolated CC18_422b, m
label var isolated "FIRE scale isolated item (5=highest resentment)"

gen FIRE=(advantages + isolated)/2
label var FIRE "2 item FIRE/modern resentment"


// Hmm, different sexism items from the ASI in 18 compared to 20.

tab CC18_422c, m
tab CC18_422d, m

factor CC18_422c CC18_422d, pcf

// complain item - highest sexism response is 1 - need to reverse
gen complain=.
replace complain=1 if CC18_422c==5
replace complain=2 if CC18_422c==4
replace complain=3 if CC18_422c==3
replace complain=4 if CC18_422c==2
replace complain=5 if CC18_422c==1

gen demands=CC18_422d
factor complain demands, pcf

gen hostilesexism18=(complain + demands)/2
label var hostilesexism18 "Hostile sexism"

// age categories 
gen age=2018-birth
label var age "Age"

// education
gen educlevel=educ
recode educlevel(2=1)
recode educlevel(3=2)
recode educlevel(4=3)
recode educlevel(5=4)
recode educlevel(6=5)
tab educlevel educ, m
label define educlevel 1 "HS or less" 2 "Some college" 3 "2 year/associate's degree" 4 "4 year/Bachelor's degree" 5 "Post-grad", replace
label values educlevel educlevel

// income
recode faminc(97=.n)


keep caseid survyr cweight2018 vweight2018 CO2reg REmandate EPA fuel18 sex partyid3 pid7 ideo5 ideo3 favors generations deserve trying resentment resentexpand advantages isolated FIRE educlevel complain demands hostilesexism age educlevel inputstate race hispanic educ religpew CC18_354a* CC18_354b* CC18_302 faminc

save CES18trimmed.dta, replace


******************************************************
******************* 2016 CES *************************
******************************************************

set more off
use CCES16_Common_OUTPUT_Feb2018_VV.dta, clear

rename V101 caseid

gen survyr=2016
gen cweight2016=commonweight
gen vweight2016=commonweight_vv

/* Main DVs 
CC16_333a: give EPA power to regulate CO2
CC16_333c: minimum renewable mandate for states
CC16_333d: strengthen CAA/CWA protection (even if costing jobs)
CC16_333b: raise fuel efficiency */

tab CC16_333a, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 CO2reg 

tab CC16_333c, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 REmandate

tab CC16_333d, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 EPA

tab CC16_333b, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 fuel16

label variable CO2reg "Give EPA power to regular CO2"
label variable REmandate "Renewable energy mandate for states"
label variable EPA "Strengthen EPA enforcement of CWA/CAA"
label variable fuel "Raise fuel efficiency standard"


// demographics

gen sex=.
label define sex 0 "Male" 1 "Female"
replace sex=0 if gender==1
replace sex=1 if gender==2
label values sex sex

tab race
tab hispanic
tab educ
tab religpew

// 3 point PID scale

gen partyid3=.
tab pid7, m
replace partyid3=1 if pid7==1
replace partyid3=1 if pid7==2
replace partyid3=1 if pid7==3
replace partyid3=3 if pid7==4
replace partyid3=3 if pid7==8
replace partyid3=2 if pid7==5
replace partyid3=2 if pid7==6
replace partyid3=2 if pid7==7
tab pid7 partyid3 , m

label define partyid3 1 "Democratic" 2 "Republican" 3 "Independent/No pref"
label values partyid3 partyid3
tab partyid3 pid7

// ideology - combine very/somewhat liberal & conservative, omit not sure

gen ideo3=ideo5
recode ideo3(2=1)
recode ideo3(5=4)
recode ideo3(6=.)
recode ideo3(3=2)
recode ideo3(4=3)
tab ideo3 ideo5, m

label define ideo3 1 "Liberal" 2 "Moderate" 3 "Conservative"
label values ideo3 ideo3
tab ideo3


/* Racial resentment  
WAIT THEY DON'T HAVE IT IN 2016 ARGH */


tab CC16_422d, m
gen advantages=CC16_422d
label var advantages "FIRE scale advantages item (5=highest prejudice)"

tab CC16_422f, m
gen isolated=.
replace isolated=1 if CC16_422f==5
replace isolated=2 if CC16_422f==4
replace isolated=3 if CC16_422f==3
replace isolated=4 if CC16_422f==2
replace isolated=5 if CC16_422f==1
tab isolated CC16_422f, m
label var isolated "FIRE scale isolated item (5=highest resentment)"

gen FIRE=(advantages + isolated)/2
label var FIRE "2 item FIRE/modern resentment"

/* ALSO - D'OH - NO SEXISM MEASURES HERE. 
Looked through the Schaffner/MacWilliams/Nteta 2018 paper - seems like it was only in a special CCES module?

*/

// age categories 
gen age=2016-birth
label var age "Age"

// education
gen educlevel=educ
recode educlevel(2=1)
recode educlevel(3=2)
recode educlevel(4=3)
recode educlevel(5=4)
recode educlevel(6=5)
tab educlevel educ, m
label define educlevel 1 "HS or less" 2 "Some college" 3 "2 year/associate's degree" 4 "4 year/Bachelor's degree" 5 "Post-grad", replace
label values educlevel educlevel

// income
recode faminc(97=.n)


keep caseid survyr cweight2016 vweight2016 CO2reg REmandate EPA fuel16 sex partyid3 pid7 ideo5 ideo3 advantages isolated FIRE age educlevel inputstate race hispanic educ religpew Hispanic_origin* Asian_origin* CC16_303 faminc

save CES16trimmed.dta, replace


******************************************************
******************* 2014 CES *************************
******************************************************

set more off 
use CCES14_Common_Content_Validated.dta, clear

rename V101 caseid

gen survyr=2014
gen cweight2014=weight

tab CC14_326_1
tab CC14_326_2
tab CC14_326_3
tab CC14_326_4

/* Main DVs 
CC14_326_1: give EPA power to regulate CO2
CC14_326_3: minimum renewable mandate for states
CC14_326_4: strengthen CAA/CWA protection (even if costing jobs)
CC14_326_2: raise fuel efficiency */

tab CC14_326_1, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 CO2reg 

tab CC14_326_3, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 REmandate

tab CC14_326_4, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 EPA

tab CC14_326_2, gen(support)
drop support2
label define support 0 "Oppose" 1 "Support", replace
label values support1 support
rename support1 fuel14

label variable CO2reg "Give EPA power to regular CO2"
label variable REmandate "Renewable energy mandate for states"
label variable EPA "Strengthen EPA enforcement of CWA/CAA"
label variable fuel "Raise fuel efficiency standard"

// demographics

gen sex=.
label define sex 0 "Male" 1 "Female"
replace sex=0 if gender==1
replace sex=1 if gender==2
label values sex sex

tab race
tab hispanic
tab educ
tab religpew

// 3 point PID scale

gen partyid3=.
tab pid7, m
replace partyid3=1 if pid7==1
replace partyid3=1 if pid7==2
replace partyid3=1 if pid7==3
replace partyid3=3 if pid7==4
replace partyid3=3 if pid7==8
replace partyid3=2 if pid7==5
replace partyid3=2 if pid7==6
replace partyid3=2 if pid7==7
tab pid7 partyid3 , m

label define partyid3 1 "Democratic" 2 "Republican" 3 "Independent/No pref"
label values partyid3 partyid3
tab partyid3 pid7

// ideology - combine very/somewhat liberal & conservative, omit not sure

gen ideo3=ideo5
recode ideo3(2=1)
recode ideo3(5=4)
recode ideo3(6=.)
recode ideo3(3=2)
recode ideo3(4=3)
tab ideo3 ideo5, m

label define ideo3 1 "Liberal" 2 "Moderate" 3 "Conservative"
label values ideo3 ideo3
tab ideo3



/* Racial resentment  
2 items from the Kinder/Sanders RR scale (Special favors/Generations of slavery items). 
*/

// need to reverse this one
gen favors=.
replace favors=1 if CC422a==5
replace favors=2 if CC422a==4
replace favors=3 if CC422a==3
replace favors=4 if CC422a==2
replace favors=5 if CC422a==1
tab favors CC422a, m

gen generations=CC422b
factor favors generations
gen resentment=(favors + generations)/2


// age categories 
gen age=2014-birthyr
label var age "Age"

// education
gen educlevel=educ
recode educlevel(2=1)
recode educlevel(3=2)
recode educlevel(4=3)
recode educlevel(5=4)
recode educlevel(6=5)
tab educlevel educ, m
label define educlevel 1 "HS or less" 2 "Some college" 3 "2 year/associate's degree" 4 "4 year/Bachelor's degree" 5 "Post-grad", replace
label values educlevel educlevel

// income
recode faminc(97=.n)

keep caseid survyr cweight2014 CO2reg REmandate EPA fuel14 sex partyid3 pid7 ideo5 ideo3 favors generations resentment age educlevel inputstate race hispanic educ religpew CC14_304 faminc

save CES14trimmed.dta, replace

append using CES16trimmed.dta
append using CES18trimmed.dta
append using CES20trimmed.dta

drop Hispanic_orig* Asian_orig* CC18* CC20*

tab race, m
replace race=3 if hispanic==1
tab race, m

gen cweight=.
replace cweight=cweight2014 if !missing(cweight2014)
replace cweight=cweight2016 if !missing(cweight2016)
replace cweight=cweight2018 if !missing(cweight2018)
replace cweight=cweight2020 if !missing(cweight2020)

label define educlevel 1 "HS or less" 2 "Some college" 3 "2 year deg" 4 "4 year deg" 5 "Post-grad", replace
label values educlevel educlevel


gen agedem=.
label define agedem 1 "18-24" 2 "25-30" 3 "31-40" 4 "41-50" 5 "51-64" 6 "65+"
replace agedem=1 if age>17 & age<25 & !missing(age)
replace agedem=2 if age>24 & age<31 & !missing(age)
replace agedem=3 if age>30 & age<41 & !missing(age)
replace agedem=4 if age>40 & age<51 & !missing(age) 
replace agedem=5 if age>50 & age<65 & !missing(age) 
replace agedem=6 if age>64 & !missing(age)
label values agedem agedem
tab age agedem, m

label var sex "Female"

tab ideo5, m
gen ideology5a=ideo5
recode ideology5a(6=.n)
label values ideology5a IDEO5

// combine all 3 vars into a single index

factor CO2 EPA RE, pcf
gen envsupport=(CO2+EPA+RE)/3 if !missing(CO2) & !missing(EPA) & !missing(RE)
label var envsupport "Index of env policy support"

tab pid7, m
codebook pid7
recode pid7 (8=.n)

codebook faminc*, tab(100)
recode faminc (31=12) (32=14)

gen income=.
replace income=faminc if !missing(faminc)
replace income=faminc_new if !missing(faminc_new)
label var income "Income"
label values income FAMINC

tab ideo5, m
codebook ideo5
gen ideodk=.
replace ideodk=0 if !missing(ideo5) & ideo5!=6
replace ideodk=1 if ideo5==6
label define ideodk 0 "Has ideological id" 1 "Not sure about ideology"
label values ideodk ideodk 

label var agedem "Age categories"
label var educlevel "Educational attainment"
label var ideology5a "Ideology"
label var survyr "Survey year"

gen hisp2=.
replace hisp2=0 if !missing(race) & !missing(hispanic)
replace hisp2=1 if race==3
replace hisp2=1 if hispanic==1

tab income
// Appx: Q1: up to $30000 (3)
// Q2: up to 50000 (5)
// Q3: up tp 70000 (7)  
// Q4: up to 100000 (10)
// Q5: above that

gen incquintile=.
replace incquintile=1 if income==1
replace incquintile=1 if income==2
replace incquintile=1 if income==3
replace incquintile=2 if income==4
replace incquintile=2 if income==5
replace incquintile=3 if income==6
replace incquintile=3 if income==7
replace incquintile=4 if income==8
replace incquintile=4 if income==9
replace incquintile=5 if income==10
replace incquintile=5 if income==11
replace incquintile=5 if income==12
replace incquintile=5 if income==13
replace incquintile=5 if income==14
replace incquintile=5 if income==15

tab income incquintile 
tab incq

label var incq "Income quintile"
label def incq 1 "Lowest quintile" 2 "Second quintile" 3 "Middle quintile" 4 "Fourth quintile" 5 "Top quintile"
label values incq incq

save CES_2014-20_replication.dta, replace
